<?php
	header('content-type:text/html;charset=utf-8');
	class ArticleAction extends Action {
		public function index(){
			
			R('Public/index');
			
			$m=M('Content');
			/*判断*/
			if($this->_get('id')){
				$id=I('get.id');
			}else{
				$id=1;
			}
			/*加点击次数*/
			$where['id']=$id;
			$num=$m->where($where)->getField('hits');
			$num++;
			$data['hits']=$num;
			$m->where($where)->save($data);
			
			$Model=new Model();
			/*原篇*/
			$sql="select c.fulltext as full_text,c.id as id,c.title as title,c.alias as alias,c.author as author,c.ptime as ptime,c.keywords as keywords,c.description as description,c.hits as hits,c.status as status,m.alias as malias,m.title as mtitle from lyolzj_content as c,lyolzj_menu as m where c.id=$id and c.menuid=m.id";
			$data=$Model->query($sql);
			$this->assign('data',$data[0]);
			
			/*上一篇*/
			if ($id>1) {
				$whereup['id']=$id-1;
				$dataup=$m->where($whereup)->find();
				$this->assign('dataup',$dataup);
			}
			
			/*下一篇*/
			$wheredown['id']=$id+1;
			$datadown=$m->where($wheredown)->find();
			$this->assign('datadown',$datadown);
			
			/*获取评论*/
			$m=M('Comment');
			import('ORG.Util.Page');// 导入分页类
			$count= $m->where(array('artid'=>$id))->count();// 查询满足要求的总记录数
			$Page= new Page($count,2);// 实例化分页类 传入总记录数和每页显示的记录数
			$show= $Page->show();// 分页显示输出
			$com['artid']=$id;
			$comment=$m->where($com)->limit($Page->firstRow.','.$Page->listRows)->select();
			if($comment!=null){
				$this->assign('comment',$comment);
			}else{
				$this->assign('comment_null','评论为空');
			}
			$this->assign('page',$show);// 赋值分页输出
			$this->display();
		}
		
		public function comment(){
			if (!$this->isAjax()){
				halt('非法操作'); 
			}
				$data=I('post.');
				$data['ctime']=date('Y-m-d H:i:s',time());
				$id=$data['artid']=I('get.id');
				$m=M('Comment');
				$m->create();
				if($m->data($data)->add()){
					$data['cname']=I('post.cname');
					$data['ctext']=I('post.ctext');
					$data['ctime']=date('Y-m-d H:i:s',time());
					$data['status']=1;
					$this->ajaxReturn($data,'json');
				}else{
					$this->ajaxReturn(0,"新增错误！",0);
				}
		}
		
	}
?>